package com.lw.nacos.client.controller;


import com.lw.nacos.client.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/provider")
public class UserClientController {
     @Value(value = "${server.port}")
     int port;
     @Autowired
     private StockService stockService;
    @PostMapping("/{username}")
    public String test(@PathVariable String username)
    {
        return "hello ,"+ username +"  i am  provider client"+port;

    }
    @PutMapping("/{productId}/{count}")
    public String deduct(@PathVariable Long productId, @PathVariable Integer count)
    {
        //休眠2秒
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stockService.deduct(productId, count);
        return "Inventory submission successful";
    }
}
